package top.yongyan0624.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.GetMapping;

import org.springframework.web.bind.annotation.RestController;
import top.yongyan0624.common.lang.ResultVO;
import top.yongyan0624.service.CardInfoService;


/**
 * @author Yongyan
 * @description: TODO
 * @date 2021/5/10
 **/

@RestController
public class TestController {

    @Autowired
    private CardInfoService cardInfoService;

    @Autowired
    private BCryptPasswordEncoder bCryptPasswordEncoder;

    @PreAuthorize("hasRole('superAdmin')")
    @GetMapping("/test")
    public Object test() {
        return cardInfoService.list();
    }

    // @PreAuthorize("hasAuthority('sys:user:list')")
    @GetMapping("/test/pwd")
    public Object pwd() {
        //密码加密
        String encode = bCryptPasswordEncoder.encode("123456");
        //验证与123456是否匹配
        boolean b = bCryptPasswordEncoder.matches("123456", encode);
        System.out.println(b);

        return ResultVO.success(encode);
    }

}
